﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Data;
namespace MyWebPagesStarterKit
{
    public class NewsTeaser : Section<NewsTeaser.Data>
    {
        public NewsTeaser(){}

        public NewsTeaser(string id) : base(id){}

        public DataView GetItems(string PageID)
        {
            WebPage page = new WebPage(PageID);
            News news = null;
            foreach (ISection section in page.Sections)
            {
                if (section.GetType().FullName.Contains("MyWebPagesStarterKit.News"))
                {
                    news = (News)SectionLoader.GetInstance().LoadSection(section.SectionId);
                    return news.GetEntriesReadonly();
                }
            }
            return null;
        }

        public override List<SearchResult> Search(string searchString, WebPage page)
        {
            return new List<SearchResult>();
        }

        public int ItemCount
        {
            get
            {
                return base._data.ItemCount;
            }
            set
            {
                base._data.ItemCount = value;
            }
        }

        public string PageID
        {
            get
            {
                return base._data.PageID;
            }
            set
            {
                base._data.PageID = value;
            }
        }

        public override bool IsOnline
        {
            get
            {
                return _data.IsOnline;
            }
            set
            {
                _data.IsOnline = value;
            }
        }

        public override Position Position
        {
            get
            {
                return _data.Position;
            }
            set
            {
                _data.Position = value;
            }
        }

        public class Data
        {
            public int ItemCount = 0;
            public string PageID;
            public bool IsOnline = true;
            public Position Position;
        }
    }
}
